package net.anzhuo.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;

import net.anzhuo.dao.GsFinanceMapper;
import net.anzhuo.entity.GsFinance;
import net.anzhuo.service.GsFinanceService;
@Service
public class GsFinanceServiceImpl implements GsFinanceService {

	@Autowired
	private GsFinanceMapper gsFinanceMapper;
	
	@Override
	public GsFinance getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsFinanceMapper.getById(id);
	}

	@Override
	public List<GsFinance> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsFinanceMapper.getBycoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsFinance> getListWithPage(GsFinance gsFinance) {
		PaginationVO<GsFinance> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsFinanceMapper.getListWithPage(gsFinance));
		paginationVO.setTotalCount(gsFinanceMapper.getCount(gsFinance.getCoMd5()));
		paginationVO.setTotalPage(((gsFinanceMapper.getCount(gsFinance.getCoMd5()) + gsFinance.getPageSize() -1)  / gsFinance.getPageSize())+1);
		paginationVO.setPageNo(gsFinance.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsFinance> getList() {
		// TODO Auto-generated method stub
		return  gsFinanceMapper.getList();
	}

	@Override
	public List<GsFinance> getList(GsFinance gsFinance) {
		// TODO Auto-generated method stub
		return gsFinanceMapper.getListByQuery(gsFinance);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsFinance gsFinance) {
		// TODO Auto-generated method stub
		gsFinanceMapper.update(gsFinance);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsFinance gsFinance) {
		// TODO Auto-generated method stub
		gsFinanceMapper.save(gsFinance);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsFinance gsCheck = gsFinanceMapper.getById(id);
		if (gsCheck == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsFinanceMapper.update(gsCheck);

	}

}
